/*
 * @author: sanbao
 * @Date: 2022-07-22 16:14:15
 */
import axios from 'axios';
import { getToken } from './auth';
import { ElLoading } from 'element-plus'

// const loading = ElLoading.service({
//     lock: true,
//     text: '拼命加载中。。。',
//     background: 'rgba(0, 0, 0, 0.7)',
// })
// const openFullScreenyes = () => {

//     setTimeout(() => {
//         loading.close()
//     }, 9999)
// }
// const openFullScreenno = () => {
//     setTimeout(() => {
//         loading.close()
//     }, 0)
// }
const request = axios.create({
    baseURL: "http://mysql.sanbao.fun:8878/api/private/v1/",
    timeout: 5000
});
request.interceptors.request.use(config => {
    // openFullScreenyes()
    config.headers = config.headers || {}
    let token = getToken()
    if (token) {
        config.headers.Authorization = token
    }
    return config
}, err => {
    return Promise.reject(err)
});

request.interceptors.response.use(res => {
    // openFullScreenno()
    return Promise.resolve(res)
}, err => {
    return Promise.reject(err)
});

export default request